package com.zhr.tea.view.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.zhr.tea.R;
import com.zhr.tea.view.activity.YCDZActivity;
import com.zhr.tea.view.activity.ZiShaActivity;
import com.zhr.tea.view.view.VerticalViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class DingZhiFragment extends Fragment {


    @BindView(R.id.dingzhi)
    VerticalViewPager dingzhi;
    private final int[] imgSource = {R.mipmap.diy_zisha, R.mipmap.diy_siren};
    List<View> viewList = new ArrayList<View>();

    public DingZhiFragment() {
        // Required empty public constructor
    }

    public static DingZhiFragment newInstance() {

        Bundle args = new Bundle();

        DingZhiFragment fragment = new DingZhiFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_ding_zhi, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        ButterKnife.bind(this, view);
        for (int i = 0; i < imgSource.length; i++) {
            View v = LayoutInflater.from(getContext()).inflate(R.layout.item_dingzhi, null);
            ImageView img = (ImageView) v.findViewById(R.id.dinghzi_iv);
            img.setImageResource(imgSource[i]);
            viewList.add(v);
        }
        dingzhi.setViewList(viewList);
        dingzhi.setOnVerticalPageChangeListener(new VerticalViewPager.OnVerticalPageChangeListener() {
            @Override
            public void onVerticalPageSelected(int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(getActivity(), ZiShaActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(getActivity(), YCDZActivity.class));
                        break;
                }
            }
        });
    }

}
